package 剑指offer;

import java.util.Arrays;

public class 扑克牌中的顺子 {
    public boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        int idx=0,num=0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]==0) {
                num++;
                continue;
            }
            else{
                idx=i;
                break;
            }
        }
        int res=0;
        for (int i = idx; i <nums.length-1; i++) {
            int curr = nums[i + 1] - nums[i];
            if (curr==0)
                return false;
            if (curr==1)
                res+=curr;
            if (curr==2){
                num--;
                res+=curr;
            }
            if (curr==3){
                num-=2;
                res+=curr;
            }
            if (curr==4){
                num-=3;
                res+=curr;
            }
        }
        if (num<0)
            return false;
        return res+num==4 || num==5 || num==4;
    }
}

